﻿using System;
using HslCommunication.ModBus;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Inovance
{
	/// <summary>
	/// 汇川的串口通信协议，适用于H5U 系列，底层走的是MODBUS-RTU协议，地址说明参见标记<br />
	/// Huichuan's serial communication protocol is suitable for H5U series. The bottom layer is MODBUS-RTU protocol. 
	/// For the address description, please refer to the mark
	/// </summary>
	/// <remarks>
	/// <inheritdoc cref="T:HslCommunication.Profinet.Inovance.InovanceH5UTcp" path="remarks" />
	/// </remarks>
	// Token: 0x02000097 RID: 151
	public class InovanceH5USerial : ModbusRtu
	{
		/// <summary>
		/// 实例化一个汇川串口协议的客户端对象<br />
		/// Instantiate a client object of Huichuan serial protocol
		/// </summary>
		// Token: 0x06000B69 RID: 2921 RVA: 0x0001A8CC File Offset: 0x00018ACC
		public InovanceH5USerial()
		{
		}

		/// <summary>
		/// 指定客户端自己的站号来初始化<br />
		/// Specify the client's own station number to initialize
		/// </summary>
		/// <param name="station">客户端自身的站号</param>
		// Token: 0x06000B6A RID: 2922 RVA: 0x0001A8D6 File Offset: 0x00018AD6
		public InovanceH5USerial(byte station = 1) : base(station)
		{
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Read(System.String,System.UInt16)" />
		// Token: 0x06000B6B RID: 2923 RVA: 0x000431BC File Offset: 0x000413BC
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 3);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Read(operateResult.Content, length);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.Byte[])" />
		// Token: 0x06000B6C RID: 2924 RVA: 0x000431FC File Offset: 0x000413FC
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 16);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000B6D RID: 2925 RVA: 0x0004323C File Offset: 0x0004143C
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 1);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.ReadBool(operateResult.Content, length);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.Boolean[])" />
		// Token: 0x06000B6E RID: 2926 RVA: 0x0004327C File Offset: 0x0004147C
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 15);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, values);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.Boolean)" />
		// Token: 0x06000B6F RID: 2927 RVA: 0x000432BC File Offset: 0x000414BC
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 5);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.Int16)" />
		// Token: 0x06000B70 RID: 2928 RVA: 0x000432FC File Offset: 0x000414FC
		[HslMqttApi("WriteInt16", "")]
		public override OperateResult Write(string address, short value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceH5UTcp.Write(System.String,System.UInt16)" />
		// Token: 0x06000B71 RID: 2929 RVA: 0x0004333C File Offset: 0x0004153C
		[HslMqttApi("WriteUInt16", "")]
		public override OperateResult Write(string address, ushort value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceH5UAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000B72 RID: 2930 RVA: 0x00043379 File Offset: 0x00041579
		public override string ToString()
		{
			return string.Format("InovanceH5USerial[{0}:{1}]", base.PortName, base.BaudRate);
		}
	}
}
